<template>
  <div class="page-style">
    <storehouse-btn @downloadFun="exportExcel" />
    <storehouse-tab :storehouse-list="storehouseList" />
    <pagination :total="total" />
  </div>
</template>

<script>
import storehouseBtn from './components/storehouse/storehouse-btn'
import storehouseTab from './components/storehouse/storehouse-tab'
import pagination from '@/components/Pagination'
import { getStorehouseInfo } from '@/api/wms'
export default {
  components: { storehouseBtn, pagination, storehouseTab },
  data() {
    return {
      total: 0,
      storehouseList: []
    }
  },
  created() {
    this.getStorehouseInfo()
  },
  methods: {
    getStorehouseInfo() {
      getStorehouseInfo().then(res => {
        this.storehouseList = res.data.list
        this.total = res.data.total
      })
    },
    exportExcel() {
      const filename = '库位信息表格'
      const header = ['仓库编号', '库位编号', '名称描述', '库存能力']
      const data = []
      const list = this.storehouseList
      for (const i in list) {
        const arr = []
        arr.push(list[i].warehouseId, list[i].storehouseId, list[i].desc, ' ' + list[i].inventory)
        data.push(arr)
      }
      import('@/vendor/Export2Excel').then(excel => {
        excel.export_json_to_excel({
          filename: filename,
          data: data,
          autoWidth: true,
          header: header
        })
      })
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
